package org.cos.verification.verifier;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class Rule {

	public int id;
	public String name;
	public String describ;
	public String content;
	
	public Rule(String name, String describ, String content) {
		this.id =  -1;this.name=name; this.describ = describ; this.content = content;
	}

	public Rule() {
		this.id =  -1;this.name=""; this.describ = ""; this.content = "";
	}

	public Rule load(byte[] raw) {
		try {
			ByteArrayInputStream bin = new ByteArrayInputStream(raw);
			DataInputStream din = new DataInputStream(bin);
			this.name = din.readUTF();
			this.describ = din.readUTF();
			this.content = din.readUTF();
			din.close();
			bin.close();
			return this;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public byte[] dump() {
		try {
			ByteArrayOutputStream bout = new ByteArrayOutputStream();
			DataOutputStream dout = new DataOutputStream(bout);
			dout.writeUTF(this.name);
			dout.writeUTF(this.describ);
			dout.writeUTF(this.content);
			byte[] raw = bout.toByteArray();
			dout.close();
			bout.close();
			return raw;
		} catch (IOException e) {
			e.printStackTrace();
			return null;

		}
	}

}
